package com.financing.wap.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.RandomStringUtils;


public class BookUtilsSend {


	public void readBook2(){
		String rfilePath = "E://book//book1.txt";
		String wfilePath = "E://book//newbook1.txt";
		String s = new String(); 
		try { 

			InputStreamReader read = new InputStreamReader(new FileInputStream(rfilePath),"GBK");//考虑到编码格式
			BufferedReader input = new BufferedReader(read); //读取流
			File file = new File(wfilePath);//写的文件

			if (!file.exists()) {
				file.createNewFile();
			}

			FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);
			/**=========================短息工具实例化===========================**/
			SMSSendUtil u = new SMSSendUtil();
			String pwd = u.encryption("123456");

			//			l.add("13795204024");
			//			l.add("15601730809");
			//			么么哒！送红包哪家强！来超级理财师，百万红包等你拿。1111元现金红包起，上不封顶，可提现 superfa.cn/t/10000
			//			去啊！1111元现金红包注册就能拿，邀请好友再拿1111元，上不封顶，还能提现哦！ superfa.cn/t/10000
			String msg1 = "么么哒！送红包哪家强！来超级理财师，百万红包等你拿。1111元现金红包起，上不封顶，可提现！ ";
			String msg2 = "去啊！1111元现金红包注册就能拿，邀请好友再拿1111元，上不封顶，还能提现哦！";
			String count = "";


			int i = 0;
			while((s = input.readLine())!=null){ //判断是否读到了最后一行
				//s就是手机号  http://www-stg.superfa.cn/wap/api/t/01/c/1
				System.out.println("手机号："+s);
				int t = Integer.valueOf(RandomStringUtils.randomNumeric(2)).intValue();
				if(t<50){
					count = msg1;
				}else{
					count = msg2;
				}
				

				List l = new ArrayList();
				i=i+1;
				String newMobile  = s+","+i;
				String url = "  superfa.cn/t/"+i;
				//////测试环境START
//				count = "去啊！1111元红包注册，邀请好友再拿111。  "+"www-stg.";
				//////测试环境END
				String sendMsg = count+""+url;
				System.out.println(sendMsg);
				l.add(s);
				u.sendSMS(l,sendMsg+"  ");//短信发送方法
				//先发送再写入
				bw.write(newMobile+"\r\n");

			} 
			bw.close();
			input.close(); 
			System.out.println("Done");
		} catch (Exception e) { 

		} 
	}

	public void wirteBook(){
		try {

			String content = "This is the content to write into file";
			File file = new File("E://book//newbook1.txt");

			if (!file.exists()) {
				file.createNewFile();
			}

			FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);
			bw.write(content);
			bw.close();

			System.out.println("Done");

		} catch (IOException e) {
			e.printStackTrace();
		}


	}

	public  static void main(String[] orgs){
		BookUtilsSend b = new BookUtilsSend();
		//b.readBook();
		System.out.println();
		//b.wirteBook();
		b.readBook2();
	}
}
